library(leaflet)
library(geojsonio)
library(jsonlite)
map = leaflet()
map = addTiles(map) %>%
setView(lng = -78.484590, lat = 38.030678, zoom = 13) %>%
addMarkers(map, lng=-78.503480, lat=38.035498, popup = "Rotunda")
map
First, the map instance must be created and stored. This action is uncommon to R, being a functional language, but must be done seperately as piping other function calls can’t be done until the map is instantiated. Tiles are then added to the map, the view determined by longitude and latitude, as well as an initial marker to identify the Rotunda. This is a basic marker, many different marker options are available for use ranging in color, shape, and opacity.
##map = addControl(map, 'html', position = c("topleft"), className = "info legend", data = getMapData(map))
map.geoJSON = map
geoJSON.trains <- "https://opendata.arcgis.com/datasets/8e1338f32fde4037b3898d10d4eac111_56.geojson"
geoJSON.roads <- "https://opendata.arcgis.com/datasets/fa6e17734a784cadbe40a3d9cf674766_30.geojson"
trains <- readLines(geoJSON.trains, warn = FALSE) %>%
paste(collapse = "\n") %>%
fromJSON(simplifyVector = FALSE)
roads <- readLines(geoJSON.roads, warn = FALSE) %>%
paste(collapse = "\n") %>%
fromJSON(simplifyVector = FALSE)
map.geoJSON = addGeoJSON(map.geoJSON, trains, layerId = NULL, group = NULL, stroke = TRUE,
color = "444444", weight = 10, opacity = 1, fill = TRUE, fillColor = "444444",
fillOpacity = 1, dashArray = NULL, smoothFactor = 1, noClip = FALSE,
options = pathOptions(), data = getMapData(map.geoJSON))
map.geoJSON = addGeoJSON(map.geoJSON, roads, layerId = NULL, group = NULL, stroke = TRUE,
color = "yellow", weight = 5, opacity = 0.5, fill = TRUE, fillColor = "yellow",
fillOpacity = 1, dashArray = NULL, smoothFactor = 1, noClip = FALSE,
options = pathOptions(), data = getMapData(map.geoJSON))
map.geoJSON